package nil.ed.simulator.request.biz.qq.scheduler;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import nil.ed.simulator.request.common.QQItem;
import nil.ed.simulator.request.scheduler.impl.PriorityScheduleUnit;

import java.util.Map;
import java.util.concurrent.Callable;

/**
 * @author lidelin.
 */
@Slf4j
public class QqLoginScheduleUnit implements PriorityScheduleUnit {

    private final Callable<Map<String, Object>> task;
    @Getter
    private final QQItem qqItem;

    public QqLoginScheduleUnit(QQItem qqItem, Callable<Map<String, Object>> task) {
        this.task = task;
        this.qqItem = qqItem;
    }

    @Override
    public boolean isTerminate() {
        return true;
    }

    @Override
    public String getBizGroup() {
        return "QQ_Login";
    }

    @Override
    public int getPriority() {
        return 0;
    }

    @Override
    public void run() {
        try {
            Map<String, Object> result = task.call();
        } catch (Exception e) {
            log.error("Failed to schedule task! ", e);
            // 1. 异常指标记录
            // 2. 事件发送
        }
    }
}
